In [3]:
%matplotlib inline
import pylab as pl
pl.plot([0,1])
Out[3]:
In [5]:
%matplotlib nbagg
import pylab as pl
pl.plot([0,1])
Out[5]:
In [7]:
%%bash
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
echo $LC_ALL
echo $LANG
In [14]:
%%bash
curl -O https://raw.githubusercontent.com/astropy/specutils/master/specutils/io/tests/files/multispec_equispec.11.dat
In [15]:
ls -lh *dat
In [112]:
#cat multispec_equispec.11.dat
In [17]:
with open('multispec_equispec.11.dat','r') as fh:
text = fh.read()
In [20]:
fh = open('multispec_equispec.11.dat','r')
text = fh.read()
fh.close()
In [34]:
with open('multispec_equispec.11.dat','r') as fh:
all_lines = []
for line in fh:
all_lines.append(line.split())
In [50]:
with open('multispec_equispec.11.dat','r') as fh:
all_lines = []
for line in fh:
all_lines.append(list(map(float, line.split())))
In [53]:
float('23.5')
Out[53]:
In [55]:
list(map(float, ["1.2","2.3"]))
Out[55]:
In [57]:
float_lines_array = np.array(all_lines)
In [61]:
float_lines_array[4,0]
Out[61]:
In [64]:
all_lines[:2]
Out[64]:
In [67]:
float_lines_array[0:3, 0]
Out[67]:
In [68]:
wavelengths = float_lines_array[:, 0]
In [69]:
fluxes = float_lines_array[:,1]
In [71]:
wavelengths_list = list(zip(*all_lines))[0]
In [72]:
a = [1,2,3]
b = ['a','b','c']
list(zip(a,b))
Out[72]:
In [73]:
list(zip(*[a,b]))
Out[73]:
given:
params = [a0,a1,a2,a3]
Equivalent:
f(a0,a1,a2,a3)
f(*params)
In [77]:
%matplotlib inline
import pylab as pl
pl.plot(wavelengths, fluxes)
pl.savefig('first_spectrum.png')
pl.savefig('first_spectrum.pdf')
In [79]:
%%bash
open first_spectrum.pdf
In [80]:
import numpy as np
In [81]:
# simple text loading
arr = np.loadtxt('multispec_equispec.11.dat')
arr
Out[81]:
In [83]:
# genfromtxt: more complicated, more flexible
arr = np.genfromtxt('multispec_equispec.11.dat')
arr
Out[83]:
In [84]:
# genfromtxt: more complicated, more flexible
# line wrapping: pep8 tells you how you "should" write code conventionally
arr = np.genfromtxt('multispec_equispec.11.dat', delimiter=" ", comments="#",
skip_header=0, skip_footer=0)
arr
In [87]:
from astropy.table import Table
from astropy.io import ascii
In [113]:
tbl = Table.read('multispec_equispec.11.dat', format='ascii.no_header', delimiter=' ')
#tbl
In [114]:
# wavelengths
#tbl['col1']
In [93]:
type(tbl['col1'])
Out[93]:
In [98]:
wavelength = tbl['col1'].data
In [99]:
wavelength
Out[99]:
In [103]:
import pandas as pd
In [108]:
pdtbl = tbl.to_pandas()
In [107]:
ptbl = pd.read_csv('multispec_equispec.11.dat', delim_whitespace=True, header=None)
In [109]:
%timeit ptbl = pd.read_csv('multispec_equispec.11.dat', delim_whitespace=True, header=None)
In [111]:
%timeit tbl = Table.read('multispec_equispec.11.dat', format='ascii.no_header', delimiter=' ')
In [115]:
tbl.
Out[115]: